package com.zcc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginController {

    @RequestMapping("/user/login")
    public String login(@RequestParam("username")String username, @RequestParam("password")String password, Model model, HttpServletRequest request) {
        if(StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
            model.addAttribute("msg","登录失败");
            return "index";
        }
        else {
            request.getSession().setAttribute("loginUser",username);
            return "dashboard";
        }
    }

    @RequestMapping("/user/logout")
    public String logout(HttpServletRequest request) {
        request.getSession().removeAttribute("loginUser");
        return "index";
    }
}
